import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/view/Home'
Vue.use(Router)


let router =  new Router({
  history: true,
  routes: [
    {
      path: "*",
      redirect: "/404"
    },
    {
      path:'/404',
      name:'Name',
      component: resolve => require(['../components/404.vue'], resolve)
    },
    {
      path: '/',
      name: 'Home',
      component: Home,
    },
    {path: '/about', component: Home},
    {path: '/shop', component: Home},
    {path: '/match', component: Home},
    {path: '/platform', component: Home},
    {path: '/sch', component: Home},
    {
      path:'/forum',
      name:'Forum',
      component: resolve => require(['../view/Forum.vue'],resolve)
    },
    {
      path:'/info',
      name:'Info',
      component: resolve => require(['../view/Info.vue'], resolve)
    },
    {
      path:'/cont',
      name:'cont',
      component: resolve => require(['../components/Editor.vue'], resolve)
    },
    {
      path:'/l',
      name:'list',
      component: resolve => require(['../view/List.vue'], resolve)
    },
    {
      path:'/news',
      name:'News',
      component: resolve => require(['../view/News.vue'], resolve)
    },
    {
      path:'/new',
      name:'NewItem',
      component: resolve => require(['../view/NewItem.vue'], resolve)
    }
  ]
})
router.beforeEach((to, from, next) => {
  if (to.matched.length ===0) {//如果未匹配到路由
    from.name ? next({ name:from.name }) : next('/');//如果上级也未匹配到路由则跳转登录页面，如果上级能匹配到则转上级路由
  } else {
    next();//如果匹配到正确跳转
  }
});
export default router;